package cn.bugstack.initializr.rigger.domain.service.module.impl;

import cn.bugstack.initializr.rigger.domain.model.ProjectInfo;
import cn.bugstack.initializr.rigger.domain.model.YmlInfo;
import cn.bugstack.initializr.rigger.domain.service.module.BaseModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.File;

/**
 * 从 https://bugstack.cn  改造而来
 * 
 * Create by 小傅哥(fustack)
*  update by 小太阳
 */
@Service
public class GenerationYml extends BaseModule {

    private Logger logger = LoggerFactory.getLogger(GenerationYml.class);

    public void doGeneration(ProjectInfo projectInfo, String projectsRoot) throws Exception {
        YmlInfo ymlInfo = new YmlInfo(projectInfo.getName());

        File file = new File(
                projectsRoot + projectInfo.getArtifactId() + "/src/main/resources/",
                "application.yml"
        );

        // 写入文件
        super.writeFile(file, "yml.ftl", ymlInfo);

        logger.info("创建配置文件 application.yml {}", file.getPath());
    }

}
